package com.study.servlet.servletconfig;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Name: GetServletConfigDemo01
* @Description: 获取ServletConfig对象方式一
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-28 下午10:07:54 
* @Version: V1.0
 */
public class GetServletConfigDemo01 extends HttpServlet {
	
	private ServletConfig config ;
	
	public void init(ServletConfig config) throws ServletException {
		this.config = config ;
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//获取Servlet名称
		String servletName = config.getServletName() ;
		//获取Servlet中的初始化参数
		System.out.println(servletName);
		Enumeration<String> dbParams = config.getInitParameterNames() ;
		while(dbParams.hasMoreElements()) {
			String paramName = (String) dbParams.nextElement() ;
			String paramValue = config.getInitParameter(paramName) ;
			System.out.println(paramName + ":" + paramValue);
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
